package com.xyf.sys.interceptor;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class ModifiedHttpServletRequest extends HttpServletRequestWrapper {

    private final String body;

    public ModifiedHttpServletRequest(HttpServletRequest request, String body) {
        super(request);
        this.body = body;
    }

    @Override
    public ServletInputStream getInputStream() {
        return new ModifiedServletInputStream(body.getBytes());
    }

    @Override
    public int getContentLength() {
        return body.getBytes().length;
    }

    @Override
    public long getContentLengthLong() {
        return body.getBytes().length;
    }

    @Override
    public String getParameter(String name) {
        // If you want to extract parameters from the modified request body, you may need to override this method
        // 根据需要可以重写该方法，从修改后的请求体中提取参数
        return super.getParameter(name);
    }
}
